<template>
  <el-button
    @click="cancelRequest('/api/common/weather/get15DaysWeatherByArea')"
    >取消请求</el-button
  >
  <el-button @click="cancelAllRequest">取消全部请求</el-button>
  <router-view></router-view>
</template>

<script setup lang = 'ts'>
import { onMounted } from "vue";
import request, { cancelRequest, cancelAllRequest } from "./server";

interface Req {
  apiKey: string;
  area?: string;
  areaID?: string;
}

interface Res {
  area: string;
  areaCode: string;
  areaid: string;
  dayList: any[];
}

const get15DaysWeather = (data: Req) => {
  return request<Req, Res>({
    url: "/api/common/weather/get15DaysWeatherByArea",
    method: "GET",
    data,
    interceptiors: {
      requestInterceptors(res) {
        console.log("拦截器");
        return res;
      },
      responseInterceptors(res) {
        console.log("拦截器");
        return res;
      },
    },
  });
};

onMounted(async () => {
  const res = await get15DaysWeather({
    apiKey: import.meta.env.VITE_APP_KEY,
    area: "北京市",
  });

  console.log(res.result.dayList);
});
</script>

<style>
</style>